﻿using PARK.Common.Const;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yitter.IdGenerator;

namespace PARK.Attend.Entitys.Entity
{
    /// <summary>
    /// 考勤规则
    /// </summary>
    [SugarTable("attend_rule")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class AttendRuleEntity
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }
        /// <summary>
        /// 上班时间
        /// </summary>
        [SugarColumn(ColumnName = "goworkdate")]
        public string goworkdate { get; set; }
        /// <summary>
        /// 下班时间
        /// </summary>
        [SugarColumn(ColumnName = "offworkdate")]
        public string offworkdate { get; set; }
        /// <summary>
        /// 最早打卡点
        /// </summary>
        [SugarColumn(ColumnName = "gopunchin")]
        public string gopunchin { get; set; }
        /// <summary>
        /// 最晚打卡点
        /// </summary>
        [SugarColumn(ColumnName = "gopunchout")]
        public string gopunchout { get; set; }
        /// <summary>
        /// 最早打卡点
        /// </summary>
        [SugarColumn(ColumnName = "offpunchin")]
        public string offpunchin { get; set; }
        /// <summary>
        /// 最晚打卡点
        /// </summary>
        [SugarColumn(ColumnName = "offpunchout")]
        public string offpunchout { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        [SugarColumn(ColumnName = "Description")]
        public string description { get; set; }
        /// <summary>
        /// 公司id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }
        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnName = "CreateDate")]
        public DateTime? CreateDate { get; set; }
        /// <summary>
        /// 创建人id
        /// </summary>
        [SugarColumn(ColumnName = "CreateUserId")]
        public string CreateUserId { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(ColumnName = "CreateUserName")]
        public string CreateUserName { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreateDate = DateTime.Now;
                this.CreateUserId = userId;
                this.CreateUserName = userName;
                this.CompanyId = App.User.FindFirst(ClaimConst.CLAINM_CompanyId)?.Value; 
                this.CompanyName = App.User.FindFirst(ClaimConst.CLAINM_CompanyName)?.Value; 
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.Id = Id;
        }
    }
}
